app.service('bankCardService',['$http','$q','utilService',function($http,$q,utilService){

    this.findAll = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'bank/card'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    //发送手机验证码
    this.getMobilePhoneCode = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'bank/card/getMobilePhoneCode',
            params:$scope.bankCardVO
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    this.confirmInfo = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'bank/card/check',
            params:$scope.bankCardVO
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    this.confirmBank = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'bank/card/check/bank',
            params:$scope.bankCardVO
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    this.confirm = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'bank/card/add',
            data:$scope.bankInfo,
            method:'POST'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.find = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'bank/card/check/count'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    this.checkAgain = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'bank/card/check/again',
            params:$scope.bankCardVO
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    this.bankCardDel = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'bank/card/del',
            data:{bankCardId:$scope.cardId},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    };
}]);